import request from "./useRequests";
import { ElMessage } from 'element-plus'
import getComments from '@/api/getComments'

export default function sendLike() {
    async function sending(userId: number, type: number, commentId: number, like: number) {
        try {
            const res = await request.put('/user/like', {
                "userId": userId,
                "type": type,
                "commentId": commentId,
                "do": like,
            })
            if (res.data.success == true) {
                return {
                    success: true,
                    status: 3 - like,
                    likeNum: res.data.data.likeNum,
                }
                // 把点赞状态传回去
            } else {
                ElMessage({
                    showClose: true,
                    message: `${res.data.message}`,
                    type: 'error',
                })
                return {
                    success: false,
                }
            }
        } catch (err: any) {
            //alert(err)
        }
    }

    return {
        sending
    }
}